package com.admgt.resource.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.admgt.resource.entity.LoadingInfo;
@Repository("LoadingInfoDao")
@Transactional
public class LoadingInfoDaoImpl implements LoadingInfoDao {

	private HibernateTemplate hibernateTemplate;
	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory){
		hibernateTemplate = new HibernateTemplate(sessionFactory);
	}
	@Override
	@Transactional(readOnly = false)
	public Object[] addGetLoadingInfo(LoadingInfo loadingInfo) {
		System.out.println("hibernateTemplate="+hibernateTemplate);
		hibernateTemplate.saveOrUpdate(loadingInfo);
		System.out.println("loadingInfo.toRowData()="+loadingInfo.toRowData());
		return loadingInfo.toRowData();
	}
	
	@Override
	@Transactional(readOnly = false)
	public int addLoadingInfo(LoadingInfo loadingInfo) {
		System.out.println("hibernateTemplate="+hibernateTemplate);
		hibernateTemplate.saveOrUpdate(loadingInfo);
		return loadingInfo.getId();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<LoadingInfo> findAllLoadingInfos() {
		return hibernateTemplate.find("from "+ LoadingInfo.class.getName());
	}

	@Override
	public LoadingInfo getLoadingInfo(int id) {
		return hibernateTemplate.get(LoadingInfo.class, id);
	}

	@Override
	@Transactional(readOnly = false)
	public void removeLoadingInfo(LoadingInfo loadingInfo) {
		hibernateTemplate.delete(loadingInfo);
	}

}
